--
-- 03/06/2012
-- doumouc_m && dourle_a
--

--- function to log a specific norme warning from the current file
-- @param msg The message to log
function warn(msg)
   if WARN[FILE] == nil then WARN[FILE] = {} end
   table.insert(WARN[FILE], {m = msg, l = LINE})
end

--- function to log a specific norme warning from a specific file
-- This function may be used in post checks
-- @param msg The message to log
-- @param filetolog the file where you want to log the warning
function warnFile(filetolog, msg)
   table.insert(WARN[filetolog], {m = msg, l = LINE})
end

--- internal function to change current file processing
-- @param name The current file to process
function enterFile(name)
   FILE = name
   table.insert(FILES, {id = name})
end

--- internal function to change current function processing
-- @param name The current function to process
function enterFunc(name, isStatic)
   FUNCTION_LEN = 0
   FUNCTION = name
   table.insert(FUNCS, {l = LINE, id = name, static = isStatic, file = FILE, callers = {}})
end

--- internal function to check if a function is called outside its file declaration
-- @param v function table
function checkCallers(v)
   for j, k in ipairs(v.callers) do
      if v.file ~= k then return; end
   end
   LINE = v.l
   if v.id ~= "main" then
      warnFile(v.file, "S;The function: " .. v.id .. " should be static")
   end
end

--- internal function to know if the text is a func proto
-- @param name The current text to process
function isFuncProto(text)
   if text ~= nil and text:byte(1) >= string.byte('a') and  text:byte(1) <= string.byte('z')  or (text:byte(1) >= string.byte('A') and  text:byte(1) <= string.byte('Z')) then
      return true
   else
      return false
   end
end